<script setup>
import { inject, ref } from "vue";
import { goPage } from "@/utils/newpage";
import { formatPrice } from "@/utils/formatPrice";
import listicon0 from "@/static/team/shopkeeper/icon-gm0.png";
import listicon1 from "@/static/team/shopkeeper/icon-gm1.png";
import listicon2 from "@/static/team/shopkeeper/icon-gm2.png";
import listicon3 from "@/static/team/shopkeeper/icon-gm3.png";
import listicon4 from "@/static/team/shopkeeper/icon-gm4.png";
import listicon5 from "@/static/team/shopkeeper/icon-gm5.png";
import listicon6 from "@/static/team/shopkeeper/icon-gm6.png";
import listicon7 from "@/static/team/shopkeeper/icon-gm7.png";
import listicon8 from "@/static/team/shopkeeper/icon-gm8.png";
import listicon9 from "@/static/team/shopkeeper/icon-gm9.png";
import listicon10 from "@/static/team/shopkeeper/icon-gm10.png";
import listicon11 from "@/static/team/shopkeeper/icon-gm12.png";
import { mine, userinfo } from "@/services/user";

// if (!user.userInfo || (user.userInfo && !user.userInfo.phone)) {
//   uni.switchTab({
//     url: "/pages/my/index",
//   });
// }

userinfofun();

const level_id = ref("");
const area_level = ref("");

async function userinfofun() {
  let res = await userinfo();
  level_id.value =
    res.data.level && res.data.level.id ? res.data.level.id : 201;
  if (res.data.area && res.data.area.level) {
    area_level.value = res.data.area.level;
  } else {
    area_level.value = "";
  }

  teamList.value.forEach((item, index) => {
    if (item.level_id) {
      if (item.level_id >= level_id.value) {
        teamList.value.splice(index, teamList.value.length);
      }
    }
    if (item.level) {
      if (area_level.value) {
        if (item.level < area_level.value) {
          teamList.value.splice(index, 1);
        }
      } else {
        teamList.value.splice(index, 1);
      }
    }
  });
  teamList2.value.forEach((item, index) => {
    if (item.level) {
      if (area_level.value) {
        if (item.level < area_level.value) {
          teamList2.value.splice(index, 1);
        }
      } else {
        teamList2.value.splice(index, teamList2.value.length);
      }
    }
  });
}

const list = ref([
  {
    name: "我的库存",
    icon: listicon1,
    num: "",
    url: "/pages/cloudlibrary/mystock/index?status=0",
  },
  {
    name: "云仓补货",
    icon: listicon2,
    num: "",
    url: "/pages/cloudlibrary/replenishment/index?status=1",
  },
  {
    name: "云仓提货",
    icon: listicon3,
    num: "",
    url: "/pages/cloudlibrary/takegood/index?status=2",
  },
  {
    name: "商品赠送",
    icon: listicon4,
    num: "",
    url: "/pages/cloudlibrary/productGift/index?status=3",
  },
  {
    name: "库存变动记录",
    icon: listicon5,
    num: "",
    url: "/pages/cloudlibrary/inventoryRecords/index?status=4",
  },
  // {
  //   name: "商家订单",
  //   icon: listicon11,
  //   num: "",
  //   url: "/pages/order/orderlist/index?status=-2",
  // },
]);

const teamList = ref([
  {
    name: "会员",
    icon: listicon0,
    num: 0,
    level_id: 101,
    url: "/pages/team/teamlist/index?type=101",
  },
  {
    name: "店主",
    icon: listicon6,
    num: 0,
    level_id: 201,
    url: "/pages/team/teamlist/index?type=201",
  },
  {
    name: "经销商",
    icon: listicon7,
    num: 0,
    level_id: 301,
    url: "/pages/team/teamlist/index?type=301",
  },
  {
    name: "服务中心",
    icon: listicon8,
    num: 0,
    url: "/pages/team/teamlist/index?type=401",
    level_id: 401,
  },
]);
const teamList2 = ref([
  {
    name: "区级独家代理",
    icon: listicon9,
    num: 0,
    url: "/pages/team/shopkeeper/area?type=3",
    level: 3,
  },
  {
    name: "市级独家代理",
    icon: listicon10,
    num: 0,
    url: "/pages/team/shopkeeper/area?type=2",
    level: 2,
  },
]);

const newPage = (item) => {
  goPage(item.url);
};
const balance = ref({});

minefun();

async function minefun() {
  let res = await mine();
  balance.value = res.data;
}

const gopayment = () => {
  uni.navigateTo({
    url: "/pages/mine/proxyPayment",
  });
};
const gobalance = () => {
  uni.navigateTo({
    url: "/pages/servicereward/myreward/balance",
  });
};

const godetlist = () => {
  uni.navigateTo({
    url: "/pages/servicereward/myreward/rewardlist",
  });
};

const goygfun = () => {
  uni.navigateTo({
    url: "/pages/servicereward/myreward/rewardyg",
  });
};

const goinvoice = () => {
  // uni.navigateTo({
  //   url: "/pages/servicereward/myreward/rewardyg",
  // });

  uni.showToast({
    title: "正在努力研发中",
    icon: "none",
  });
};
</script>
<template>
  <view class="work">
    <view class="work-banner">
      <view class="work-banner-list">
        <view class="list-index">
          <view class="list-index-left">云仓库存管理</view>
        </view>
      </view>
      <view class="user-order user-list-gn">
        <view
          class="user-order-item"
          v-for="(item, index) in list"
          :key="index"
          @click="newPage(item)"
        >
          <uni-badge
            class="uni-badge-left-margin"
            :text="item.num"
            absolute="rightTop"
            size="small"
          >
            <image :src="item.icon" mode="widthFix" />
            <view class="user-order-name">{{ item.name }}</view></uni-badge
          >
        </view>
      </view>
    </view>
    <view class="work-banner">
      <view class="work-banner-list">
        <view class="list-index">
          <view class="list-index-left">团队管理</view>
        </view>
      </view>
      <view class="user-order user-list-gn">
        <view
          class="user-order-item"
          v-for="(item, index) in teamList"
          :key="index"
          @click="newPage(item)"
        >
          <image :src="item.icon" mode="widthFix" />
          <view class="user-order-name">{{ item.name }}</view>
        </view>
        <view
          class="user-order-item"
          v-for="(item, index) in teamList2"
          :key="index"
          @click="newPage(item)"
        >
          <image :src="item.icon" mode="widthFix" />
          <view class="user-order-name">{{ item.name }}</view>
        </view>
      </view>
    </view>

    <view class="work-banner">
      <view class="foodr-list">
        <view class="list-index">
          <view class="list-index-left">我的收入</view>
          <view class="list-index-right" @click="godetlist"
            >余额变动明细
            <image
              src="@/static/team/shopkeeper/icon-gm11.png"
              mode="widthFix"
            ></image>
          </view>
        </view>
      </view>

      <u-line></u-line>
      <view class="work-middle">
        <view class="work-middle-left">
          <view class="middle-left-top">账户余额（元）</view>
          <view class="middle-left-footer"
            >￥{{ formatPrice(balance.balance || 0) }}</view
          >
        </view>
        <view class="work-middle-right">
          <view class="middle-right-bt" @click="gopayment">代付</view>
          <view class="middle-right-bt withdrawal" @click="gobalance"
            >提现</view
          >
        </view>
      </view>
      <u-line></u-line>

      <view class="work-banner-footer">
        <view class="work-footer-box">
          <view class="left-box">
            <view class="work-left-text">预估收入</view>
            <view class="work-middle-img">
              <uni-tooltip
                class="item"
                content="未出账的预估收益"
                placement="right"
              >
                <view class="item">
                  <u-icon name="question-circle"></u-icon
                ></view>
              </uni-tooltip>
            </view>
            <view class="work-money" @click="goygfun"
              >￥{{ formatPrice(balance.expected_reward || 0) }}</view
            >
          </view>
        </view>
        <view class="work-footer-box">
          <view class="left-box">
            <view class="work-left-text">提现中</view>
            <view class="work-money"
              >￥{{ formatPrice(balance.settle_balance || 0) }}</view
            >
          </view>
        </view>
      </view>
    </view>

    <view class="work-banner" @click="goinvoice">
      <view class="foodr-list">
        <view class="list-index">
          <view class="list-index-left">
            <image
              src="@/static/team/invoice-icon.png"
              mode="widthFix"
            />开具发票</view
          >
          <view class="list-index-right">
            <image
              src="@/static/team/shopkeeper/icon-gm11.png"
              mode="widthFix"
            ></image>
          </view>
        </view>
      </view>
    </view>
  </view>
</template>

<style lang="scss" scoped>
@import "./work.scss";
</style>
